var rootPath = getRootPath();
var uid;
$(function() {
	//获取跳转系统
	var system = getParentUrlParam("system");
	$.ajax({
		url: rootPath + '/user/queryUserself',
        type: 'GET',
        contentType: 'application/json;charset=UTF-8',
        success: function (data) {
        	if(data.returnCode == undefined) {
        		return;
        	}
        	if(data.returnCode == '0000') {
        		var user = data.returnObject;
        		if(user.headimgurl != null && user.headimgurl != undefined ) {
					$("#headimgurl").prop("src", rootPath + "/file/viewimg?fileName=" + user.headimgurl + "&type=1");
				}
				//页面"昵称"对应数据库uname
				$("#nickName").html(user.uname);
				$("#authPhone").html(user.phone != '' ? user.phone : user.email);
				uid = user.uid;
				createQR(uid,system);
        	} else {
        		layer.alert(data.returnMessage);
        	}
        },
        error: function (jqXHR, textStatus, errorThrown) {
        	layer.alert("error");
        }
    });
});

function createQR(uid,system) {
	var redirectUri = redirect_uri;
	if(system != null && system != '' && system.toLowerCase() == 'scfire') {
		redirectUri += encodeURIComponent("?system=scfire")
	}
	
	var obj = new WxLogin({
		id:"wx",//div的id
		appid : appid,
		scope : scope,
		redirect_uri : redirectUri,
		state : hex_md5("bind" + uid) + "_" + uid,
		style : style,        
		href : rootPath + "/normal/css/layouts/bindWechat/_all.css"
	 });
}